define(['app'], function(app) {
    app.controller('PasswordEditController', ['Dialog', 'Context', 'UserService',
        function(Dialog, Context, UserService) {
        var self = this;

        self.password = '';
        self.newPassword = '';
        self.confirmPassword = '';

        self.init = function() {
            // init
        };

        self.save = function(valid) {
            if (valid) {
                if (self.newPassword != self.confirmPassword) {
                    return;
                }
                UserService.savePassword({
                    password: self.password,
                    newPassword: self.newPassword
                }).then(function(resp) {
                    if (resp.success) {
                        Context.success = true;
                        Dialog.$alert('密码修改成功！').then(function() {
                            Context.closeAll();
                        });
                    }
                });
            }
        };
    }]);
});
